import {
  Component,
  Injector,
  ViewEncapsulation,
  ViewChild,
  ElementRef,
} from "@angular/core";
import { AppComponentBase } from "@shared/common/app-component-base";
import {
  PipelineListDto,
  OrganizationUnitServiceProxy,
  ComboboxItemDto,
  BatchTaskServiceProxy,
  BatchDto,
  GetOutsourcingTaskInfoDto,
  //CreateConfirmInfoDto,
} from "@shared/service-proxies/service-proxies";
import { finalize } from "rxjs/operators";
import { appModuleAnimation } from "@shared/animations/routerTransition";

@Component({
  selector: "zl5",
  templateUrl: "./zl5.component.html",
  encapsulation: ViewEncapsulation.None,
  animations: [appModuleAnimation()],
})
export class ZL5ModalComponent extends AppComponentBase {
  saving = false;

  pipe: PipelineListDto = new PipelineListDto();
  batch = new BatchDto();
  outsourcing: GetOutsourcingTaskInfoDto[];
  selectedoutsourcing = new GetOutsourcingTaskInfoDto();
  deliveryAmount = 0;
  noPassedAmount = 0;
  quantityAmount = 0;

  constructor(
    injector: Injector,
    private _taskServiceProxy: BatchTaskServiceProxy
  ) {
    super(injector);
  }

  load(pipe: PipelineListDto): void {
    this.pipe = pipe;
    this._taskServiceProxy.getBatch(pipe.taskId).subscribe((result) => {
      this.batch = result;
      if (this.batch != null) {
        this.deliveryAmount = this.batch.certificateQuantity;
      }
    });
    this._taskServiceProxy.getTaskInfos(pipe.taskCode).subscribe((result) => {
      this.outsourcing = result;
      if (this.outsourcing != null) {
        this.selectedoutsourcing = this.outsourcing[0];
      }
    });
  }

  save(): void {
    // console.log(this.selectedoutsourcing);
    // if(this.selectedoutsourcing==null){
    //     return this.notify.error('请选择外协确认单');
    // }
    // this.saving = true;
    // var data=new CreateConfirmInfoDto();
    // data.subtask=this.pipe.barCode;
    // data.outsourcingTaskId=this.selectedoutsourcing.id;
    // data.deliveryCode=this.selectedoutsourcing.requisitionCode;
    // data.qualityControlCardNo=this.batch.certificateId;
    // data.deliveryAmount=this.deliveryAmount;
    // data.passedAmount=this.batch.certificateQuantity;
    // data.noPassedAmount=this.noPassedAmount;
    // data.quantityAmount=this.quantityAmount;
    // this._taskServiceProxy
    //     .createConfirmInfoByMesData(
    //         data
    //     )
    //     .pipe(
    //         finalize(() => {
    //             this.saving = false;
    //         })
    //     )
    //     .subscribe((result) => {
    //         this.notify.success('确认成功');
    //     });
  }
}
